<template>
  <view class="package_sale column" style="margin: 0px;height: 100vh;justify-content: space-between;">
    <image src="../../static/icon/top.png" mode="" style="width: 430rpx;height: 340rpx;margin-top:15vh;"></image>
    <view class="center login" @click="login()">
      <uni-icons type="weixin" size="30" color="#fff" style="margin-right: 10rpx;"></uni-icons>
      微信登录
    </view>
    <view class="package_sale">{{a}}</view>
    <view class="center" style="margin-bottom: 5vh;">
      <uni-icons :type="show?'checkbox-filled':'circle'" size="20" :color="show?'#35A2E7':'#333'"
        style="margin-right: 10rpx;" @click="()=>show=!show"></uni-icons>
      阅读并同意用户<text style="color:#35A2E7;" @click="navTo('Information/richText?type=login')">《服务协议》</text>及<text
        style="color:#35A2E7;" @click="navTo('Information/richText?type=login')">《隐私政策》</text>
    </view>
  </view>
</template>

<script setup lang="ts">
  import { navTo, navToTab } from '@/utils/navigator';
  import { errorToast, successToast } from '@/utils/prompt';
  import { ref } from 'vue';
  const a = ref('')
  const show = ref(false)
  function login() {
    //验证有无安装微信
    // #ifdef APP-PLUS
    let isWx = plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' });
    if (!isWx) {
      errorToast('请先安装微信APP')
      return;
    }
    // #endif
    if (!show.value) {
      errorToast('请阅读并同意用户协议')
      return;
    }
    // #ifdef APP-PLUS
    uni.login({
      "provider": "weixin",
      "onlyAuthorize": true,
      success: function (event) {
        uni.request({
          url: 'https://admin.anlan.tech/api/v1/login/wxApp_login',
          data: {
            code: event.code
          },
          success: (res) => {
            console.log(res)
            a.value = JSON.stringify(res.data.data.userinfo)
            uni.setStorageSync('driver_ID',res.data.data.userinfo.id)
            successToast('登录成功')
            setTimeout(() => {
              navToTab('index')
            }, 1000)
          }
        });
      },
      fail: function (err) {
        console.log(err)
      }
    })
    // #endif
  }
</script>

<style scoped lang="less">
  .login {
    margin-top: 20vh;
    width: 647rpx;
    height: 98rpx;
    background: linear-gradient(187deg, #35A2E7, #45B1F4);
    border-radius: 10rpx;
    justify-content: center;
    color: #fff;
  }
</style>